You can use the procedures Comp3to1 and Comp6to1 to compress sound data. You can use the procedures Exp1to3 and Exp1to6 to expand compressed audio data.
You can use the Comp3to1 procedure to compress sound data at a ratio of 3:1.
PROCEDURE Comp3to1 (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt;
inState: Ptr; outState: Ptr;
numChannels: LongInt; whichChannel: LongInt);
The Comp3to1 procedure compresses cnt samples of sound stored in the buffer specified by inBuffer and places the result in the buffer specified by outBuffer , which must be at least cnt/3 bytes in size. The original samples can be monophonic or include multiple channels of sound, but they must be in 8-bit offset binary format. Also, if numChannels is greater than 1, then the noncompressed sound must be stored in interleaved format on a sample basis.
If you compress polyphonic sound, you retain only one channel of sound, which you specify in the whichChannel parameter. Thus, if you use the Comp3to1 procedure to compress three-channel sound, you will have effectively compressed the sound to one-ninth its original size in bytes. To retain multiple channels of sound after compression, you must call the Comp3to1 procedure for each channel to be compressed and then interleave the compressed sound data on a packet basis.
The Comp3to1 procedure compresses every 48 bytes of sound data to exactly 16 bytes of compressed sound data and compresses remaining bytes to no more than one-third the original size.
You can use the inState and outState parameters to allow the MACE compression routines to preserve information about algorithms across calls. Alternatively, you may pass NIL state buffers and let the Sound Manager allocate the buffers internally.
You can use the Comp6to1 procedure to compress sound data at a ratio of 6:1.
PROCEDURE Comp6to1 (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt;
inState: Ptr; outState: Ptr;
numChannels: LongInt; whichChannel: LongInt);
The Comp6to1 procedure compresses cnt samples of sound stored in the buffer specified by inBuffer and places the result in the buffer specified by outBuffer , which must be at least cnt/6 bytes in size. The Comp6to1 procedure works much like the Comp3to1 procedure, but compresses every 48 bytes of sound data to exactly 8 bytes of compressed sound data and compresses remaining bytes to no more than one-sixth the original size.
You can use the Exp1to3 procedure to expand a buffer of sound samples you previously have compressed with the Comp3to1 procedure.
PROCEDURE Exp1to3 (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt;
inState: Ptr; outState: Ptr;
numChannels: LongInt; whichChannel: LongInt);
The Exp1to3 procedure expands cnt packets of sound stored in the buffer specified by inBuffer and places the result in the buffer specified by outBuffer , whose size must be at least cnt packets * 2 bytes per packet * 3, or cnt * 6 bytes. If numChannels is greater than 1, then the compressed sound must be stored in interleaved format on a packet basis.
If you expand compressed sound data that includes multiple sound channels, you retain only one channel of sound, which you specify in the whichChannel parameter. Thus, if you use the Exp1to3 procedure to expand three-channel sound, the output buffer will be the same size as the input buffer since only one channel is retained. To retain multiple channels of sound after expansion, you must call the Exp1to3 procedure for each channel to be expanded and then interleave the expanded sound data on a sample basis.
The Exp1to3 procedure expands every packet of sampled-sound data to exactly 6 bytes.
You can use the inState and outState parameters to allow the MACE compression routines to preserve information about algorithms across calls. Alternatively, you may pass NIL state buffers and let the Sound Manager allocate the buffers internally.
You can use the Exp1to6 procedure to expand a buffer of sound samples you previously have compressed with the Comp6to1 procedure.
PROCEDURE Exp1to6 (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt;
inState: Ptr; outState: Ptr;
numChannels: LongInt; whichChannel: LongInt);
The Exp1to6 procedure expands cnt packets of sound stored in the buffer specified by inBuffer and places the result in the buffer specified by outBuffer , whose size must be at least cnt packets * 1 byte per packet * 6, or cnt * 6 bytes. If numChannels is greater than 1, then the compressed sound must be stored in interleaved format on a packet basis. The Exp1to6 procedure works just like the Exp1to3 procedure, but expands 1-byte packets rather than 2-byte packets.
| Previous | Chapter contents | Chapter top | Section top | Next |